
var oTuZi;//方块对象
(function(){
	var timer=30; //每运行一段距离所运行的距离
	var bg="white"; //背景色;
	
	oTuZi=function(){
		
	}
	oTuZi.prototype.init=function(){
		
		oTuZi.prototype.createRect(OBODY)
	}
	oTuZi.prototype.createRect=function(OBODY){
		var oDiv; //生成的块;
		var oDivImg; //生成块中的敌人;
		var timers=2000; //多少秒创建一次
		var numIndex=0;
		var loseNum=0;//丢失的个数;
		var tmpScore=5;//临时减分;
		LOSEOBJ = document.getElementById(DS);
		setInterval(function(){createNums()},timers)
		
		function createNums()
		{	
			numIndex++;
			var width = 80+Math.floor(Math.random()*50);  //宽度
			var height = width*.3;  //高度
			var top = parseInt(Math.floor(Math.random()*parseInt(CLIENTHEIGHT)))-70;
			if(top<70) top=70;		
			oDiv = document.createElement("div")
			oDivImg = document.createElement("img")
			oDivImg.setAttribute("src",FJARR[Math.floor(FJARR.length*Math.random())])
			oDivImg.setAttribute("style","width:"+100+"%;")
			oDiv.setAttribute("numIndex",numIndex)
			oDiv.setAttribute("style","width:"+width+"px;position:absolute;left:"+-width+"px;top:"+top+"px;cursor:pointer;");
			oDiv.appendChild(oDivImg);
			OBODY.appendChild(oDiv);
			move(oDiv);//移动
			del_ff(oDiv)
		}
		
		function del_ff(elem){
			var elem_child = elem.childNodes;
			for(var i=0; i<elem_child.length;i++)
			{
				if(elem_child[i].nodeName == "#text" && !/\s/.test(elem_child.nodeValue))
				{
					elem.removeChild(elem_child)
				}
			}
		}
		
		//移动;
		function move(oDiv)
		{
			var thisSpeed=0;
			oDiv.setAttribute("speed",Math.floor(2+Math.random()*5))
			//20毫秒运行10个像素,1980的距离;
			var clearA = setInterval(function(){
				thisSpeed+=parseInt(oDiv.getAttribute("speed"));
				oDiv.style.left=thisSpeed+"px";
			},timer)
			//运行完总距离就释放空间内存;
			var clearB = setTimeout(function(){
				if(oDiv.getAttribute("numIndex")!="none")
				{
					//逃跑的元素;
					loseNum++
					console.log(loseNum)
					LOSEOBJ.value=""+loseNum;
					SCOREOBJ.value = (SCOREOBJ.value-=tmpScore)
					OBODY.removeChild(oDiv);
					CLEARBARR.pop();
					clearInterval(clearA)
					clearTimeout(clearB)
				}
			},CLIENTWIDTH/parseInt(oDiv.getAttribute("speed"))*timer)
			CLEARBARR.push(clearB);
		}
	}
	
	
	
	//击中则清除元素;
	oTuZi.prototype.clearEventElement=function(e)
	{		
		e.style.filter='alpha(opacity=0)';
		e.style.opacity=0;
		//设置标记索引为none则为清除;
		e.setAttribute("numIndex","none")
		OBODY.removeChild(e)
	}
})();

		